package com.cyzy.mapper;

import com.cyzy.dto.ClassDO;
import com.cyzy.dto.User;
import com.cyzy.dto.UserSignIn;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CameraMapper {

    @Insert("insert into user_face (user_id,face_token) values (#{userId},#{faceToken})")
    int addFace(String userId, String faceToken);


    @Select("select user.*,user_sign_in.time from user_sign_in JOIN user ON user.id=user_sign_in.user_id  where sign_statues=1 and live_name=#{liveName}")
    List<User> getUserSignIn(String liveName);

    @Update("update user_sign_in set sign_statues=#{statues},time = NOW() where user_id=#{userId} and live_name = #{liveName}")
    int updateUserSignIn(String userId, int statues ,String liveName);


    @Insert("insert into user_sign_in (user_id,class_code,sign_statues,live_name) values (#{userId},#{classId},0,#{liveName})")
    int addUserSignOut(String userId, String classId,String liveName);

    @Select("select * from class")
    List<ClassDO> getAllClass();

    //获取班级的所有学生信息
    @Select("select * from user where class_id=#{classId} and role = 0")
    List<User> getAllStudents(String classId);

    //查询签到
    @Select("select * from user_sgin_in where user_id = #{userId}")
    List<UserSignIn> findByUserId(String userId);

}
